fix: eliminate port race in setupFakeEnvoyStats test helper - #9580
Merged
Conversation
✅ Deploy Preview for cerulean-figolla-1f9435 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
net.Listen(":0") followed by l.Close() and a later ListenAndServe() on
the resulting port number leaves a window where another process (or a
concurrently running test) can grab that exact ephemeral port before
the re-bind happens, causing TestGetTotalConnections to fail with
connection errors on loaded machines. Serve on the already-bound
listener directly via s.Serve(l) so the port is never released.
Signed-off-by: Muhammad Waqar <mwaqar@confluent.io>
muwaqar-cflt
force-pushed
the
fix/shutdown-manager-port-race
branch
from
July 25, 2026 06:45
4b91931 to
256ac64
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9580 +/- ##
==========================================
- Coverage 75.64% 75.59% -0.05%
==========================================
Files 252 252
Lines 41758 41758
==========================================
- Hits 31589 31569 -20
- Misses 8046 8062 +16
- Partials 2123 2127 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
/retest |
arkodg
approved these changes
Jul 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
setupFakeEnvoyStatsininternal/cmd/envoy/shutdown_manager_test.gobinds an ephemeral port withnet.Listen(":0"), immediately closes that listener, and later re-binds to the same port number vias.ListenAndServe(). This is a classic time-of-check-to-time-of-use race: betweenl.Close()and the goroutine'sListenAndServe()actually completing its bind, another process (or a concurrently running test) can grab that exact port number, causingTestGetTotalConnectionsto fail intermittently on loaded machines with errors likeerror getting listener downstream_cx_active stat: Get ..., while the real cause (fail to listen: ...) is only printed to stdout rather than failing the test directly.Fix
Keep the original
net.Listenerand calls.Serve(l)instead ofs.ListenAndServe(), so the already-bound listener is reused and the port is never released and re-acquired.Test plan
go build ./...go test -race -run TestGetTotalConnections -count=200 ./internal/cmd/envoy/...— clean